关于sql语句中条件语句where后的多个and/or的优先级 您所在的位置:网站首页 select where and 关于sql语句中条件语句where后的多个and/or的优先级

关于sql语句中条件语句where后的多个and/or的优先级

#关于sql语句中条件语句where后的多个and/or的优先级| 来源: 网络整理| 查看: 265

摘要:

    SQL的WHERE子句中包含多个AND和OR

示例:

    SQL解析器在处理操作时会优先处理and操作:

    假如有表product字段如下:id、product_id、product_price、product_name,现在要查找产品号为100或者101,并且价格大于200的商品,程序员可能会这样写:            select * from product where product_id = 100 or product_id = 101 and product_price > 200

    上述代码中,SQL解析器首先进行and 的操作,最后就成了这个意思:查找产品号为101且价格大于200或产品号为100 的商品。

添加圆括号即可:

select * from product where (product_id = 100 or product_id = 101) and product_price > 200

sql注入中的万能密码一般都会多加几个or,username' or 1=1 or 1=1 --+



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有